package smedi.ismedi.web.bff.controller.organization;

import com.smedi.ismedi.organization.api.dto.request.HrOrganizationRequest;
import com.smedi.ismedi.organization.api.dto.request.OrganizationListQueryRequest;
import com.smedi.ismedi.organization.api.dto.request.OrganizationOneQueryRequest;
import com.smedi.ismedi.organization.api.dto.request.TwoHrOrganizationNodeRequest;
import com.smedi.ismedi.organization.api.dto.response.HrOrganizationResponse;
import com.smedi.ismedi.organization.api.dto.response.resp.OrganizationResp;
import com.smedi.ismedi.organization.api.feign.RemoteHrOrganizationFeignApi;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import smedi.ismedi.web.bff.controller.BaseController;

import java.util.List;
import java.util.Map;

/**
 * 企业组织管理
 *
 * @author xulinjun
 */
@Slf4j
@RestController
@Api(tags = {"企业组织架构维护接口"})
@RequestMapping("/webbff/v1/hrOrganization")
@AllArgsConstructor
public class HrOrganizationController extends BaseController {
    private final RemoteHrOrganizationFeignApi remoteHrOrganizationFeignApi;

    /**
     * 保存行政组织信息
     *
     * @param hrOrganizationRequest
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "保存组织信息")
    @PostMapping(value = "/save")
    public ResponseData<HrOrganizationResponse> postSaveHrOrganization(@RequestBody HrOrganizationRequest hrOrganizationRequest) {
        return remoteHrOrganizationFeignApi.postSaveHrOrganization(hrOrganizationRequest);
    }

    /**
     * 保存行政组织信息
     *
     * @param hrOrganizationId
     */
    @ApiOperation(httpMethod = "DELETE", value = "删除组织信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class),
    })
    @DeleteMapping(value = "/delete")
    public ResponseData<Boolean> deleteHrOrganization(@RequestParam("hrOrganizationId") Long hrOrganizationId) {
        return remoteHrOrganizationFeignApi.deleteHrOrganization(hrOrganizationId);
    }

    /**
     * 查询行政组织树
     *
     * @param hrOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "查询组织树")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/getHrOrganizationTree")
    public ResponseData<List<HrOrganizationResponse>> getHrOrganizationTree(@RequestParam(value = "hrOrganizationId", required = false) Long hrOrganizationId) {
        return remoteHrOrganizationFeignApi.getHrOrganizationTree(hrOrganizationId);
    }

    /**
     * 无安全性查询组织树
     *
     * @param hrOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "无安全性查询组织树")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/getHrOrganizationTreeNoSecurity")
    public ResponseData<List<HrOrganizationResponse>> getHrOrganizationTreeNoSecurity(@RequestParam(value = "hrOrganizationId", required = false) Long hrOrganizationId) {
        return remoteHrOrganizationFeignApi.getHrOrganizationTreeNoSecurity(hrOrganizationId);
    }

    /**
     * 查询行政组织视图
     *
     * @param hrOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "查询组织视图")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/getHrOrganizationView")
    public ResponseData<HrOrganizationResponse> getHrOrganizationView(@RequestParam(value = "hrOrganizationId") Long hrOrganizationId) {
        return remoteHrOrganizationFeignApi.getHrOrganizationView(hrOrganizationId);
    }

    /**
     * 判断当前职能组织是否可以用
     *
     * @param hrOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "判断当前组织是否可以用")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/checkAvailable")
    public ResponseData<Boolean> getCheckAvailable(@RequestParam(value = "hrOrganizationId") Long hrOrganizationId) {
        return remoteHrOrganizationFeignApi.getCheckAvailable(hrOrganizationId);
    }

    /**
     * 获取当前组织下的所有子节点组织id及其本身
     *
     * @param hrOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "获取当前组织下的所有子节点组织id及其本身")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class)
    })
    @GetMapping(value = "/getHrOrganizationChildrenOrgIdList")
    public ResponseData<List<Long>> getHrOrganizationChildrenOrgIdList(@RequestParam(value = "hrOrganizationId") Long hrOrganizationId) {
        return remoteHrOrganizationFeignApi.getHrOrganizationChildrenOrgIdList(hrOrganizationId);
    }

    /**
     * 获取当前组织下的所有子节点组织id与组织名称及其本身
     *
     * @param hrOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "获取当前组织下的所有子节点组织id与组织名称及其本身")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class)
    })
    @GetMapping(value = "/getHrOrganizationChildrenOrgMap")
    public ResponseData<Map<Long, String>> getHrOrganizationChildrenOrgMap(@RequestParam(value = "hrOrganizationId") Long hrOrganizationId) {
        return remoteHrOrganizationFeignApi.getHrOrganizationChildrenOrgMap(hrOrganizationId);
    }

    /**
     * 判断当前职能组织下是否允许创建项目
     *
     * @param hrOrganizationId
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "判断当前职能组织下是否允许创建项目")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationId", value = "企业组织id", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping(value = "/checkHrOrganizationCanHasProjectAvailable")
    public ResponseData<Boolean> getCheckHrOrganizationCanHasProjectAvailable(@RequestParam(value = "hrOrganizationId") Long hrOrganizationId) {
        return remoteHrOrganizationFeignApi.getCheckHrOrganizationCanHasProjectAvailable(hrOrganizationId);
    }

    /**
     * 根据企业组织id数组获取企业组织信息
     *
     * @param hrOrganizationIds
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "根据企业组织id数组获取企业组织信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "hrOrganizationIds", value = "企业组织id数组", dataType = "List", dataTypeClass = List.class),
    })
    @GetMapping(value = "/queryHrOrganizationList")
    public ResponseData<List<HrOrganizationResponse>> getQueryHrOrganizationList(@RequestParam(value = "hrOrganizationIds") List<Long> hrOrganizationIds) {
        return remoteHrOrganizationFeignApi.getQueryHrOrganizationList(hrOrganizationIds);
    }

    /**
     * 根据组织名称模糊查询企业组织列表
     *
     * @param fullName
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "根据组织名称模糊查询企业组织列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "fullName", value = "企业组织名称", dataType = "String", dataTypeClass = String.class),
    })
    @GetMapping(value = "/queryHrOrganizationListByFullName")
    public ResponseData<List<HrOrganizationResponse>> getQueryHrOrganizationListByFullName(@RequestParam(value = "fullName") String fullName) {
        return remoteHrOrganizationFeignApi.getQueryHrOrganizationListByFullName(fullName);
    }

    /**
     * 获取所有企业组织下的项目管理组织清单
     *
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "获取所有企业组织下的项目管理组织清单")
    @GetMapping(value = "/queryAllProjectManagementHROrganizationList")
    public ResponseData<List<HrOrganizationResponse>> getQueryAllProjectManagementHROrganizationList() {
        return remoteHrOrganizationFeignApi.getQueryAllProjectManagementHROrganizationList();
    }

    /**
     * 获取所有企业组织下的特定类型的组织清单
     *
     * @return
     */
    @ApiOperation(httpMethod = "GET", value = "获取所有企业组织下的特定类型的组织清单")
    @GetMapping(value = "/queryAllHROrganizationListByType")
    ResponseData<List<HrOrganizationResponse>> getQueryAllHROrganizationListByType(@RequestParam("isCompany") boolean isCompany,
                                                                                   @RequestParam("isCompanyLeader") boolean isCompanyLeader,
                                                                                   @RequestParam("isCompanyManagementOrganization") boolean isCompanyManagementOrganization,
                                                                                   @RequestParam("isProjectManagementOrganization") boolean isProjectManagementOrganization,
                                                                                   @RequestParam("isSubordinateOrganization") boolean isSubordinateOrganization) {
        return remoteHrOrganizationFeignApi.getQueryAllHROrganizationListByType(isCompany, isCompanyLeader, isCompanyManagementOrganization, isProjectManagementOrganization, isSubordinateOrganization);
    }

    /**
     * 交换两个企业组织的排序，并获取企业组织树
     *
     * @param twoHrOrganizationNodeRequest
     * @return
     */
    @ApiOperation(httpMethod = "POST", value = "交换两个企业组织的排序，并获取企业组织树")
    @PostMapping(value = "/exchangeTwoHrOrganizationNodeSort")
    ResponseData<List<HrOrganizationResponse>> postExchangeTwoHrOrganizationNodeSort(@RequestBody TwoHrOrganizationNodeRequest twoHrOrganizationNodeRequest) {
        return remoteHrOrganizationFeignApi.postExchangeTwoHrOrganizationNodeSort(twoHrOrganizationNodeRequest);
    }

    /**
     * 查询 企业 详情
     *
     * @param organizationOneQueryRequest 企业 详情 请求
     * @return ResponseData<List < OrganizationResp>>
     */
    @PostMapping(value = "/one")
    @ApiOperation(httpMethod = "POST", value = "查询 企业组织 单一")
    ResponseData<OrganizationResp> getOrganizationOne(@RequestBody OrganizationOneQueryRequest organizationOneQueryRequest) {
        return remoteHrOrganizationFeignApi.getOrganizationOne(organizationOneQueryRequest);
    }

    /**
     * 查询 企业 列表
     *
     * @param organizationListQueryRequest 企业 列表 请求
     * @return ResponseData<List < OrganizationResp>>
     */
    @PostMapping(value = "/list")
    @ApiOperation(httpMethod = "POST", value = "查询 企业组织 列表")
    ResponseData<List<OrganizationResp>> getOrganizationList(@RequestBody OrganizationListQueryRequest organizationListQueryRequest) {
        return remoteHrOrganizationFeignApi.getOrganizationList(organizationListQueryRequest);
    }
}
